package com.itqf.controller;

import com.itqf.entity.ScheduleJob;
import com.itqf.service.SchedulerService;
import com.itqf.utils.Pager;
import com.itqf.utils.R;
import com.itqf.utils.ResultData;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 徐老板
 * @date 2020/1/31   9:46
 */
@RestController
public class SchedulerContrller {
    @Resource
    private SchedulerService schedulerService;

    @RequestMapping("/schedule/job")
    private String fanhui(){
        return "/schedule/job";
    }

    @RequestMapping("/schedule/job/list")
    private ResultData scheduleList(Pager pager,String search){
        ResultData resultData = schedulerService.schedulerList(pager, search);
        return resultData;
    };

    @RequestMapping("/schedule/job/save")
    private R saveScheduleJob(@RequestBody ScheduleJob scheduleJob) throws SchedulerException {
//        System.out.println("controller层的"+scheduleJob);

        return schedulerService.save(scheduleJob);
    }

    @RequestMapping("/schedule/job/update")
    private R updateScheduleJob(@RequestBody ScheduleJob scheduleJob){
        return schedulerService.update(scheduleJob);
    }

    @RequestMapping("/schedule/job/info/{jobId}")
    private R getScheduleJob(@PathVariable Long jobId){
        return schedulerService.get(jobId);
    }

    @RequestMapping("/sys/job/del")
    private R deleteScheduleJob(@RequestBody List<Long> jobIds){
        return schedulerService.delete(jobIds);
    }

    @RequestMapping("/sys/job/pause")
    private R pauseScheduleJob(@RequestBody List<Long> jobIds){
        return schedulerService.pause(jobIds);
    }

    @RequestMapping("/sys/job/resume")
    private R resumeScheduleJob(@RequestBody List<Long> jobIds){
        return schedulerService.resume(jobIds);
    }

    @RequestMapping("/sys/job/run")
    private R runScheduleJob(@RequestBody List<Long> jobIds){
        return schedulerService.run(jobIds);
    }

}
